package sv.ues.fia.adminperfildocentes;

import java.util.ArrayList;

import sv.ues.fia.adminperfildocentes.adapter.GridviewAdapter;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class AdministradorActivity extends Activity {
	
	private GridviewAdapter mAdapter;
	private ArrayList<String> listTitulo;
	private ArrayList<Integer> listCatalogo;
	private ArrayList<String> listClass;
	private GridView gridView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_administrador);
		
		prepareList();
        
        // prepared arraylist and passed it to the Adapter class
        mAdapter = new GridviewAdapter(this,listTitulo, listCatalogo);
        
        // Set custom adapter to gridview
        gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(mAdapter);
        
        // Implement On Item click listener
        gridView.setOnItemClickListener(new OnItemClickListener() 
        {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
							
				try{
					String nombreValue=listClass.get(position);
	    			Class<?> clase=Class.forName("sv.ues.fia.adminperfildocentes."+nombreValue);
	    			 Intent inte = new Intent(getApplicationContext(), clase);
	    			startActivity(inte);
	    		}catch(ClassNotFoundException e){
	    			e.printStackTrace();
	    			Toast.makeText(AdministradorActivity.this,"Class not found", Toast.LENGTH_SHORT).show();
	    		}
	    		
			}
		});
	}

	public void prepareList()
    {
    	  listTitulo = new ArrayList<String>();
    	  
    	  listTitulo.add(getResources().getString(R.string.cargo_icon));
    	  listTitulo.add(getResources().getString(R.string.empresa_icon));
    	  listTitulo.add(getResources().getString(R.string.escalafon_icon));
    	  listTitulo.add(getResources().getString(R.string.especializacion_icon));
    	  listTitulo.add(getResources().getString(R.string.formacion_icon));
    	  listTitulo.add(getResources().getString(R.string.grado_icon));
    	  listTitulo.add(getResources().getString(R.string.idioma_icon));
    	  listTitulo.add(getResources().getString(R.string.institucion_icon));
    	  listTitulo.add(getResources().getString(R.string.pais_icon));
    	  listTitulo.add(getResources().getString(R.string.usuario_icon));
    	  //listTitulo.add(getResources().getString(R.string.salir_icon));
    	  
         
          listCatalogo = new ArrayList<Integer>();
          listCatalogo.add(R.drawable.cargo_icon);
          listCatalogo.add(R.drawable.empresa_icon);
          listCatalogo.add(R.drawable.escalafon_icon);
          listCatalogo.add(R.drawable.especializacion_icon);
          listCatalogo.add(R.drawable.formacion_icon);
          listCatalogo.add(R.drawable.grado_icon);
          listCatalogo.add(R.drawable.idioma_icon);
          listCatalogo.add(R.drawable.institucion_icon);
          listCatalogo.add(R.drawable.pais_icon);
          listCatalogo.add(R.drawable.usuario_icon);
          //listCatalogo.add(R.drawable.salir_icon);
          
          listClass = new ArrayList<String>();
          listClass.add("ListarCargosActivity");
    	  listClass.add("ListarEmpresasActivity");
    	  listClass.add("ListarEscalafonActivity");
    	  listClass.add("ListarEspecializacionesActivity");
    	  listClass.add("ListarFormacionesActivity");
    	  listClass.add("ListarGradosActivity");
    	  listClass.add("ListarIdiomasActivity");
    	  listClass.add("ListarInstitucionesActivity");
    	  listClass.add("ListarPaisesActivity");
          listClass.add("ListarUsuarioActivity");
    }
	
	public void callListaDocente(View v)
	{
		Intent intent = new Intent(this, ListarDocentesActivity.class);
		startActivity(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.administrador, menu);
		return true;
	}

	@SuppressWarnings("deprecation")
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.opt_sobre:
			AlertDialog alertDialog = new AlertDialog.Builder(this).create();
			
		    // Setting Dialog Title
		    alertDialog.setTitle(getString(R.string.sobre));
		
		    // Setting Dialog Message
		    alertDialog.setMessage(getString(R.string.msjAcercappal));
		
		    // Setting Icon to Dialog
		    alertDialog.setIcon(R.drawable.ic_menu_help);
		
		    // Setting OK Button
		    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
		            public void onClick(DialogInterface dialog, int which) {
		           
		            }
		    });
		
		    // Showing Alert Message
		    alertDialog.show();
			return (true);
		case R.id.opt_ayuda:
			AlertDialog alertDialog2 = new AlertDialog.Builder(this).create();
		
		    // Setting Dialog Title
		    alertDialog2.setTitle(getString(R.string.ayuda));
		
		    // Setting Dialog Message
		    alertDialog2.setMessage(getString(R.string.msjAyudappal));
		
		    // Setting Icon to Dialog
		    alertDialog2.setIcon(R.drawable.ic_menu_help);
		
		    // Setting OK Button
		    alertDialog2.setButton("OK", new DialogInterface.OnClickListener() {
		            public void onClick(DialogInterface dialog, int which) {
		           
		            }
		    });
		
		    // Showing Alert Message
		    alertDialog2.show();
			return (true);
		case R.id.opt_cerrar:
			this.finish();
			Intent intent = new Intent(this, PrincipalActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			return (true);
		
		}
		return (super.onOptionsItemSelected(item));
	}
	


}
